<?php
/**
 * 高级搜索
 * @author liuxiaoqing <liuxiaoqing@zhishisoft.com>
 * @version TS3.0
 */
class ArtistAction extends Action 
{
	
	/**
	 * 
	 * 
	 * @author diccn
	 * 2014-9-20
	 */
	public function index(){
		$this->display();
	}
	/**
	 * 标签搜索
	 * 
	 * @author diccn
	 * 2014-9-20
	 */
	public function tag(){
		if(!empty($_POST['location'])){
			$_POST['location'] = t($_POST['location']);
			$map['location'] = array('like',"%{$_POST['location']}%");
		}
		if(!empty($_POST['tag'])){
			$_POST['tag'] = explode(',',str_replace('，' , ',' , t($_POST['tag'])));
			foreach ( $_POST['tag'] as $key=>$val){
				$tag_map[] = "tag like '%{$val}%'";
			}
			$map['_string'] = implode(' or ',$tag_map);
		}
		$list = M('user_tag')->field("ut.*,count(ut.tag_id) as 'utotal' ")->join("as ut LEFT JOIN ts_user as u ON ut.uid = u.uid")->where($map)->group('ut.tag_id')->findAll();
		$first_letter_array = array_unique(getSubByKey($list,'first_letter'));
		sort($first_letter_array);
		foreach ($first_letter_array as $k=>$v){
			$data['list'][$k]['first_letter'] = $v;
			foreach ($list as $key => $val){
				if( $v == $val['first_letter'] ){
					$val['total'] = M('user_tag')->where("tag_id = {$val['tag_id']}")->count();
					$val['percentage'] = ceil($val['utotal'] / $val['total'] * 100) ;
					$data['list'][$k]['tags'][] = $val;
				}
			}
		}
		$this->assign($data);
		$this->display();
	}
	/**
	 * 位置搜索
	 *
	 * @author diccn
	 * 2014-9-20
	 */
	public function location(){
		if(!empty($_POST['location'])){
			$_POST['location'] = t($_POST['location']);
			$map['location'] = array('like',"%{$_POST['location']}%");
		}
		if(!empty($_POST['tag'])){
			$_POST['tag'] = explode(',',str_replace('，' , ',' , t($_POST['tag'])));
			foreach ( $_POST['tag'] as $key=>$val){
				$tag_map[] = "tag like '%{$val}%'";
			}
			$map['_string'] = implode(' or ',$tag_map);
		}
		$data['list'] = model('User')->where($map)->order("ctime DESC")->findPage(20);
		foreach ( $data['list']['data'] as $key=>$val){
			$data['list']['data'][$key]['user_info'] = model('User')->getUserInfo($val['uid']);
			if(!empty($data['list']['data'][$key]['user_info']['user_tag'])){
				$tags = getSubByKey($data['list']['data'][$key]['user_info']['user_tag'],'tag_name');
				$data['list']['data'][$key]['user_info']['user_tag'] = implode(',',$tags);
			}
			$data['list']['data'][$key]['userData'] = model('UserData')->getUserData($val['uid']);
			$val['follow_state'] = model("Follow")->getFollowState($GLOBALS['ts']['mid'], $val['uid']);
			$data['list']['data'][$key]['follow_state'] = $val['follow_state']['following'].$val['follow_state']['follower'];
			$data['list']['data'][$key]['work_list'] = model('Works')->getUserNew3($val['uid']);
		}
		$this->assign($data);
		$this->display();
	}
    
}